<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bottomVisible</title>
    <style>
        .test {
            min-height: 400vh;
        }

        .container {
            width: 60%;
            height: 400px;
            margin: auto;
            transform: scale(0);
            opacity: 0;
            transition: transform .4s cubic-bezier(0.075, 0.82, 0.165, 1), opacity .4s cubic-bezier(0.075, 0.82, 0.165, 1);
        }

        .container.show {
            transform: scale(1);
            opacity: 1;
        }

        .img-box {
            position: relative;
            height: 0;
            --aspect-ratio--: 16 / 9;
            padding-bottom: calc(100% / (var(--aspect-ratio--)));

        }

        .img-box>.img {
            position: absolute;
            object-fit: cover;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div class="test">滚动页面到底部</div>
    <div class="container">
        <div class="img-box">
            <img src="./1.png" alt="测试图片" class="img">
        </div>
    </div>
    <script>
        const debounce = (handler, ms) => {
            let time = null;
            return function (...args) {
                clearTimeout(time);
                time = setTimeout(() => handler.apply(this, args), ms);
            }
        }
        const bottomVisible = () => {
            const { clientHeight, scrollHeight } = document.documentElement;
            const { scrollY } = window;
            return clientHeight + scrollY >= (scrollHeight || clientHeight);
        };
        const box = document.querySelector('.container')
        window.addEventListener('scroll', debounce(() => {
            if (bottomVisible()) {
                box.classList.add('show')
            } else {
                box.classList.remove('show')
            }
        }, 1000))
    </script>
</body>

</html>